package com.wj.dubbo.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.wj.console.ICrawlerService;
import com.wj.console.common.exception.BusinessException;
import com.wj.console.rabbit.message.CrawlerSocialFundMessage;
import com.wj.console.rpc.RpcRequest;
import com.wj.console.rpc.RpcResponse;
import com.wj.dubbo.service.crawler.service.impl.CrawlFundService;
import com.wj.dubbo.service.crawler.service.impl.CrawlSocialService;

@Service(timeout=20000, connections=2)
public class CrawlerService implements ICrawlerService{
	private final Logger logger = LoggerFactory.getLogger(CrawlerService.class);

	@Autowired
	private CrawlSocialService socialServiceImpl;
	@Autowired
	private CrawlFundService crawlFundService;
	
	@Override
	public RpcResponse<CrawlerSocialFundMessage> querySocial(RpcRequest<CrawlerSocialFundMessage> request) {
		RpcResponse<CrawlerSocialFundMessage> response =new RpcResponse<CrawlerSocialFundMessage>();
		try {
			response.setData(socialServiceImpl.crawSocialData(request.getParam()));
		} catch (BusinessException e) {
			logger.error("爬取社保数据【业务】异常:"+e.getCode(), e);
			response.setResultCode(e.getCode());
		} catch (Exception ex){
			logger.error("【SYSTEM】爬取社保数据异常", ex);
			response.setResultCode(response.SYSTEM_ERROR);
		}catch (Throwable exx){
			logger.error("【SYSTEM】爬取社保数据异常", exx);
			response.setResultCode(response.SYSTEM_ERROR);
		}
		return response;
	}

	@Override
	public RpcResponse<CrawlerSocialFundMessage> queryFund(RpcRequest<CrawlerSocialFundMessage> request) {
		RpcResponse<CrawlerSocialFundMessage> response = new RpcResponse<CrawlerSocialFundMessage>();
		try {
			response.setData(crawlFundService.crawlFundData(request.getParam()));
		} catch (BusinessException e) {
			logger.error("爬取公积金数据【业务】异常:"+e.getCode(), e);
			response.setResultCode(e.getCode());
		} catch (Exception ex){
			logger.error("【SYSTEM】爬取公积金数据异常");
			response.setResultCode(response.SYSTEM_ERROR);
		}catch (Throwable exx){
			logger.error("【SYSTEM】爬取公积金数据异常", exx);
			response.setResultCode(response.SYSTEM_ERROR);
		}
		return response;
	}


}
